<?php
$articleId=getParameter("articleId");


$show=getParameter("show");
if (!isset($portlet_shop_articledisplay_SplitDescription) || $portlet_shop_articledisplay_SplitDescription=="") $portlet_shop_articledisplay_SplitDescription="no";



if ($articleId!=null)
{

?>
<script type="text/javascript">
var quantities=Array();

function getQuantity(id){

	for (var i=0;i<quantities.length;i++)
	{
if (quantities[i].id==id) return quantities[i].quantity;
		}
	return null;
}
  </script>
  


<?php


//$sSql="SELECT * FROM shop_articles WHERE shop_articles.id=".$id." and shop_articles.portalId = ".$portalId;

if (!getParameter($portletUID."_question_submit"))
{
$sSql="UPDATE shop_articles SET countView=countView+1 WHERE id=".$articleId;
$GLOBALS["conn"]->Execute($sSql);
}

$sSql="SELECT DISTINCT
shop_articles.id,
shop_articles.lib_$LANG as lib,
shop_articles.price,
shop_articles.reference,
shop_articles.brandId,
shop_articles.description_$LANG as description,
shop_articles.shortdescription_$LANG as shortdescription,
shop_articles.details_$LANG as details,
shop_articles.availability as availability,
shop_articles.weight as weight,
shop_articles.height as height,
shop_articles.width as width,
shop_articles.depth as depth,
shop_articles.infospratic as infospratic,
shop_articles.countItems as countItems,
shop_articles.file as file,
shop_gallery.picture,
shop_gallery.picture_large,
shop_gallery.id as pictureid
FROM
shop_articles
INNER JOIN shop_gallery ON shop_articles.id = shop_gallery.articleId
WHERE shop_articles.id=".$articleId." and shop_gallery.default='Y' and
shop_articles.portalId = ".$portalId;

//echo $sSql;
Portal_log($sSql);
$rs=$GLOBALS["conn"]->Execute($sSql);

$hauteur=$rs->fields["height"];
$longueur=$rs->fields["width"];
$profondeur=$rs->fields["depth"];
$infospratiques=$rs->fields["infospratic"];
$nbrcolis=$rs->fields["countItems"];
$poids=$rs->fields["weight"];


$pictureid=$rs->fields["pictureid"];
$price=$rs->fields["price"];
$reference=$rs->fields["reference"];
$details=$rs->fields["details"];
$libelle=$rs->fields["lib"];
$file=$rs->fields["file"];
$shortdescription=$rs->fields["shortdescription"];
    $portlet_description=preg_split("/[\n]+/",$rs->fields["description"]);
if  ($price=="" || $price<=0) $price="N/A";
    $pagetitle = $rs->fields["lib"];



if ($rs->RecordCount()>0) {

$sSql="SELECT * FROM shop_gallery WHERE articleId=".$articleId;
    $max_quantity=$rs->fields["availability"];

Portal_log($sSql);
$rs_gallery=$GLOBALS["conn"]->Execute($sSql);


	  ?>

	  <div class="articlesview">

	<div class="retour">
	<div class="btn-retour"><a href="javascript:history.back()"><span>RETOUR </span></a></div>
	<div class="imprimer"><a href="javascript:window.print()"><img src="http://media-cdn.fly.fr/skin/frontend/fly_fr/default/images/catalog/product/print.png" width="23" height="20" alt="Imprimer cette page" title="Imprimer cette page"></a></div>
</div>


<div class="images ">
<div class="fb-like" data-send="true" data-width="450" data-show-faces="true" data-layout="button_count" data-font="segoe ui" data-colorscheme="dark"></div>
		<div class="image radius5">
		
		 <table width="100%" height="100%" align="center" valign="center">
   <tr><td>
   <div id="imageholder">
     
     
     
     
     <?php if (!isset($app_shop_watermark)) { ?>
 <img id="picture_<?=$pictureid?>" rel="image_src" alt='Facebook' src="<?php echo getFilesPath("gallery",false)."/".$rs->fields["picture"]; ?>" data-zoom-image="<?php echo getFilesPath("gallery",false)."/".$rs->fields["picture_large"]; ?>"  />
<?php } else { ?>

<img id="picture_<?=$pictureid?>" rel="image_src" alt='Facebook' src="/apps/watermark.php?image=<?php echo getFilesPath("gallery",false)."/".$rs->fields["picture"]; ?>&stamp=<?php echo "/".getFilesPath("image")."/".$app_shop_watermark; ?>" data-zoom-image="/apps/watermark.php?image=<?php echo getFilesPath("gallery",false)."/".$rs->fields["picture_large"]; ?>&stamp=<?php echo "/".getFilesPath("image")."/".$app_shop_watermark; ?>"  />
<?php } ?>
     
     
     </div>
            <?php
            $FB_image ="http://".getPortalHost().getFilesPath("gallery",false)."/".$rs->fields["picture"];
            $FB_description=$rs->fields["description"];
            ?>
   </td></tr>
   </table>


</div>



 <div id="article_images" class="article_images">
  	  <?php

 while ( !$rs_gallery->EOF)  { 
 	
 	$imgpath=getFilesPath("gallery",false)."/".$rs_gallery->fields["picture"];
 	$imglargepath=getFilesPath("gallery",false)."/".$rs_gallery->fields["picture_large"];
 	$cpictureid=$rs_gallery->fields["id"];
		  ?>


<!-- onclick="changeimage(<?=$cpictureid?>)" -->
		 
		 
		 
		      <?php if (!isset($app_shop_watermark)) { ?>
 
  <a  href="#"  class="min  frame"  data-image="<?=$imgpath?>"  data-zoom-image="<?=$imglargepath?>" > <img id="picture_<?=$pictureid?>" src="<?php echo $imgpath; ?>"   /></a>
<?php } else { ?>


<a  href="#"  class="min  frame"  data-image="/apps/watermark.php?image=<?=$imgpath?>&stamp=<?php echo "/".getFilesPath("image")."/".$app_shop_watermark; ?>"  data-zoom-image="/apps/watermark.php?image=<?=$imglargepath?>&stamp=<?php echo "/".getFilesPath("image")."/".$app_shop_watermark; ?>" > <img id="picture_<?=$pictureid?>" src="/apps/watermark.php?image=<?php echo $imgpath; ?>&stamp=<?php echo "/".getFilesPath("image")."/".$app_shop_watermark; ?>"   /></a>
<?php } ?>
     
		 
		
		  	  <?php
			
		  $rs_gallery->MoveNext();    
		  }

		 ?>
	<script type="text/javascript">

	/*function changeimage(id){

		$("#picture_<?=$pictureid?>").attr("src",$("#image_"+id).attr("src"));
		$("#picture_<?=$pictureid?>").attr("data-zoom-image",$("#image_"+id).attr("data"));
	

		 $.removeData($("#picture_<?=$pictureid?>"), 'elevateZoom');//remove zoom instance from image

	        $('.zoomContainer').remove();// remove zoom container from DOM

		$("#picture_<?=$pictureid?>").elevateZoom({
			  zoomType				: "outer",
			  cursor: "crosshair"
			});

				

		}*/


		$("#picture_<?=$pictureid?>").elevateZoom({gallery:'article_images',zoomType: "inner", cursor: 'crosshair', galleryActiveClass: 'active', imageCrossfade: false, loadingIcon: 'http://www.elevateweb.co.uk/spinner.gif'});


		//pass the images to Fancybox
		$("#picture_<?=$pictureid?>").bind("click", function(e) {  
		  var ez =   $('#picture_<?=$pictureid?>').data('elevateZoom');	
			$.fancybox(ez.getGalleryList());
		  return false;
		});
		 

		//pass the images to Fancybox
		$("#zoom_03").bind("click", function(e) {  
		  var ez =   $('#zoom_03').data('elevateZoom');	
			$.fancybox(ez.getGalleryList());
		  return false;
		});

	  $(document).ready(function() {

			/* This is basic - uses default settings */
			
		//	$("a.min").fancybox();
	  });
	</script>
	<!-- <div class="zoom" ><?php echo $var_shop_clicktozoom; ?></div> -->
	 </div> </div>
	
<div class="fiche">
	  <form action="/cart.html" method="POST">
<input type="hidden" value="<?php echo getParameter("articleId"); ?>" name="articleId">
<div class="product-main-info">
<div class="ref">Réference <?=$reference?></div>

<div class="libelle"><?php echo $libelle; ?> 
<?php if ($rs->fields["brandId"]!=0) { ?>
          <div class="brand">Par <a href="#"><?php echo getObjByKey("shop_brands","lib_lt","id",$rs->fields["brandId"]); ?></a></div>
              <?php } ?>
    <?php if ($app_shop_hasPrice=="yes" && $price!=0) { ?>
    
        <?php } ?>
    </div>
    
    <div class="shortdesc"><?=$shortdescription?></div>
<div class="prix"><?php echo "  ".formatMoney($price,true); ?> <?php echo $app_shop_currency; ?></div>



</div>


<div class="product-main-info">

   <!--Description-->
    <?php  if  (trim($rs->fields["description"])!=""){ ?>
<b><?php echo $var_shop_description; ?></b>


    <?php      if ($portlet_shop_articledisplay_SplitDescription=="yes") { ?>
        <ul class="description">
            <?php

            foreach ($portlet_description as $item)
            {

                ?>
                <li><?php echo $item; ?></li>

                <?php

            }

            ?>
        </ul>

        <?php
    }else{

    ?>
              <div class="description"><?php echo $rs->fields["description"]; ?>
              </div>
        <?php } ?>


          <?php } ?>
          <?php if ($file!="") {?>
<a class="pdf" href="<?=getFilesPath("shop_files",false)."/".$file?>">Fiche technique</a>
<?php }?>
</div>


<div class="product-main-info">

<?php if ($app_shop_hasStock=="yes") {?>
    <div class="availability">

        <div id="stockin"> <img src="/images/icons/instock.png"/><?php echo $var_shop_instock; ?></div>
        <div id="stockout"><img src="/images/icons/outofstock.png"/><?php echo $var_shop_offstock; ?></div>
        <?php

        if ($max_quantity>0) { ?>
            <script type="text/javascript">

                $("#stockout").hide();

            </script>
        <?php } else { ?>
            <script type="text/javascript">

                $("#stockin").hide();

            </script>
        <?php } ?>

        <?php if ($app_shop_hasUnit=="yes") { ?>
            <script type="text/javascript">

                $("#stockout").hide();

            </script>
        <?php } ?>


    </div>
<?php } ?>




    <?php //$show!="units"
    if (false) { ?>
    
    
    

          <!--Details-->
<?php  if  (trim($rs->fields["details"])!=""){ ?>
<b><?php echo $var_shop_details; ?></b>
<div class="details"><?php echo $rs->fields["details"]; ?></div>
    <?php } ?>
<?php 

//getObjByKey("")
?>


<?php if ($app_shop_hasUnit=="yes") { ?>
<!--<a href="<?php echo createNiceUrl("pageName",getParameter("pageName"),"articleId",getParameter("articleId"),"show","units"); ?>"><b><?php echo $var_shop_SIZES; ?></b></a>-->
<table>
<tr>
<?php 

$sSql="SELECT
shop_unit.availability,
shop_sizes.size
FROM
shop_unit
INNER JOIN shop_sizes ON shop_unit.size = shop_sizes.id
WHERE
shop_unit.articleId=".$articleId." AND shop_unit.availability > 0";



Portal_log($sSql);
$rs_size=$GLOBALS["conn"]->Execute($sSql);
while ( !$rs_size->EOF)  {
	?>

		  <td> <div class="size"><input type="radio" name="size" value="<?php echo $rs_size->fields["size"]; ?>" id="size_<?php echo $rs_size->fields["size"]; ?>" /><br/>
		 <?php echo $rs_size->fields["size"]; ?>
		 
		 <script type="text/javascript">

             quantities.push({id:<?php echo $rs_size->fields["size"]; ?>,quantity:<?php echo $rs_size->fields["availability"]; ?>})
  
          </script>
		</div>
</td>
		  	  <?php
		  	  $max_quantity=$rs_size->fields["availability"];			
		  $rs_size->MoveNext();    
		  }
?>
</tr></table>
<br/>
<?php }
      }
   if ($app_shop_hasUnit=="yes") {
          ?>
          <b><?php echo $var_shop_SIZES; ?></b>

<div class="units">

              <?php


          $sSql="SELECT
*
FROM
shop_unit
WHERE
shop_unit.articleId=".$articleId." AND shop_unit.availability > 0";



          Portal_log($sSql);
          $rs_units=$GLOBALS["conn"]->Execute($sSql);
          while ( !$rs_units->EOF)  {
              ?>

              <div class="unit">

             <a href="<?php echo getFilesPath("shop_unit",false)."/".$rs_units->fields["picture"]; ?>" class="">
<img src="<?php echo getFilesPath("shop_unit",false)."/".getthumbname($rs_units->fields["picture"]); ?>" />
             </a><br>
 <input type="radio" name="unit" value="<?php echo $rs_units->fields["id"]; ?>" id="unit_<?php echo $rs_units->fields["id"]; ?>" />
             <?php echo $rs_units->fields["lib"]; ?>

              </div>
              <script type="text/javascript">

                  quantities.push({id:<?php echo $rs_units->fields["id"]; ?>,quantity:<?php echo $rs_units->fields["availability"]; ?>})

              </script>
              <?php

              $rs_units->MoveNext();
          }
          ?>

</div>

<br clear="all"/>
          <?php

      }
    $cansee=true; ///&& $show!="units"
    if ($app_shop_hasUnit=="yes" ) { $cansee=false; }

        if($app_shop_hasQuantity=="yes" && $cansee && $max_quantity>0){



          ?>
<br clear="all"/>
<b><?php echo $var_shop_quantity_title; ?></b>
          <div class="quantity">
              <div>
<input type="text" id="quantity" name="quantity" value="1" size="4" /><input type="button" value="+" id="inc"><input type="button" value="-" id="dec">
              </div>


          </div>
              <?php } else { ?> <input type="hidden" id="quantity" name="quantity" value="1" size="1" /><?php } ?>


              
               <?php    if($app_shop_hasCart=="yes" && $cansee ){  ?>
              <br clear="all"/>
<input type="submit" value="<?php echo $var_shop_addtocart; ?>" name="<?php echo $portletUID; ?>submit" class="button"/>
    <?php } ?>
</div>























<div>
   
<?php if (false) { ?>
    <input type="button" value="<?php echo $var_shop_sendtofriend; ?>" name="<?php echo $portletUID; ?>submit" class="button" onclick="$('#sendtofriend').slideDown();$('#question').hide()"/>
<input type="button" value="<?php echo $var_shop_askquestion; ?>" name="<?php echo $portletUID; ?>submit" class="button" onclick="$('#question').slideDown();$('#sendtofriend').hide();"/>
<?php } ?>
</div>
  </form>

<div id="question" class="border">
<form class="std" action="<?php echo createUrl(); ?>" method="POST">
<p class="required text">
			<label for="name"><?php echo $var_shop_yourname; ?></label>
			<?php 
			$_REQUEST[$portletUID."name"]=getUserFullname();
			formText($portletUID."name",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		<p class="required text">
			<label for="mail"><?php echo $var_shop_yourmail; ?></label>
			<?php
            if (isset($_SESSION["login"])) $_REQUEST[$portletUID."mail"]=$_SESSION["login"];
			formText($portletUID."mail",0,"account_input"); ?>
			<sup>*</sup>
		</p>
	<p class="required textarea">
			<label for="mail"><?php echo $var_shop_question; ?></label>
			<?php formTextArea($portletUID."question",30,5,"account_input"); ?>
			<sup>*</sup>
		</p>
<p >
    <label for="" style="color:white">&nbsp;</label>
<input type="submit" value="<?php echo $var_shop_submit; ?>" name="<?php echo $portletUID; ?>_question_submit" class="button"/>
</p>
</form>

</div>

  <?php if (getParameter($portletUID."_question_submit"))
  {
  	$question=getParameter($portletUID."question");
  	$name=getParameter($portletUID."name");
  	$mail=getParameter($portletUID."mail");
  	$error=false;
  	
  	if ($mail==null || ew_CheckEmail($mail)==FALSE) displayError($var_shop_validnmailerror,$portletUID."mail");
  	
  	if ($name==null) displayError($var_shop_validnameerror,$portletUID."name");
  	
  	if ($question==null) displayError($var_shop_validquestionerror,$portletUID."question");
  	
  	if (!$error){
  		echo "<br/><br/>";
  	ShowSuccess($var_shop_questionsaved);
  	$sSql="INSERT INTO shop_questions (articleId,question,date,name,mail,portalId) values(".$articleId.",'".$question."','".ew_CurrentDateTime()."','".$name."','".$mail."',".$portalId.")";
  	$GLOBALS["conn"]->Execute($sSql);

  	sendMailToAdmins($portalId, $var_shop_mail_questionsavedadmin);


    $data=array();
    $data["name"]=$name;
  	sendMailTo($mail, TemplateWithData($var_shop_mail_questionsaved,$data));
  	}
  }
  
  ?>
  
  <div id="sendtofriend" class="border">
<form class="std" action="<?php echo createUrl(); ?>" method="POST">
<p class="required text">
			<label for="name"><?php echo $var_shop_yourname; ?></label>
			<?php 
			$_REQUEST[$portletUID."name"]=getUserFullname();
			formText($portletUID."name",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		<p class="required text">
			<label for="mail"><?php echo $var_shop_yourmail; ?></label>
			<?php
            if (isset($_SESSION["login"])) $_REQUEST[$portletUID."mail"]=$_SESSION["login"];
			formText($portletUID."mail",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		
		<p class="required text">
			<label for="name"><?php echo $var_shop_yourfriend; ?></label>
			<?php formText($portletUID."friendname",0,"account_input"); ?>
			<sup>*</sup>
		</p>
		<p class="required text">
			<label for="mail"><?php echo $var_shop_yourfriendmail; ?></label>
			<?php formText($portletUID."friendmail",0,"account_input"); ?>
			<sup>*</sup>
		</p>
	
<p >
<label for="" style="color:white">&nbsp;</label>
<input type="submit" value="<?php echo $var_shop_submit; ?>" name="<?php echo $portletUID; ?>_sendtofriend_submit" class="button"/>
</p>
</form>
</div>
 <?php if (getParameter($portletUID."_sendtofriend_submit"))
  {
  	$question=getParameter($portletUID."question");
  	$name=getParameter($portletUID."name");
  	$mail=getParameter($portletUID."mail");
  	$friendname=getParameter($portletUID."friendname");
  	$friendmail=getParameter($portletUID."friendmail");
  	$error=false;
  	
  	if ($mail==null || ew_CheckEmail($mail)==FALSE) displayError($var_shop_validnmailerror,$portletUID."mail");
  	
  	if ($name==null) displayError($var_shop_validnameerror,$portletUID."name");
  	
  	if ($friendmail==null || ew_CheckEmail($friendmail)==FALSE) displayError($var_shop_validmailfrienderror,$portletUID."mail");
  	 
  	if ($friendname==null) displayError($var_shop_validnamefrienderror,$portletUID."name");
  	 
  	
  	if (!$error){
  		
  		$host=EW_PORTAL_URL;
  		if (isLocal())  $host=getPortalUrl().".betasite.net";
  		
  		echo "<br/><br/>";
       ShowSuccess($var_shop_senttofriend);
          $data=array();
          $data["name"]=$name;
          $data["host"]=$host;
          $data["friendname"]=$friendname;
          $data["friendmail"]=$friendmail;
          $data["articleId"]=$articleId;

  	sendMailToAdmins($portalId, TemplateWithData($var_shop_mail_senttofriendadmin,$data));



          $data=array();
          $data["name"]=$name;
          $data["host"]=$host;
          $data["friendname"]=$friendname;
          $data["friendmail"]=$friendmail;
          $data["articleId"]=$articleId;
          $data["portal"]=getPortalName();

  	sendMailTo($friendmail, TemplateWithData($var_shop_mail_senttofriend,$data));
  	}
  }
  
  ?>


  
  
</div>

<br clear="all"/>
<div id="product_tabs" class="product_tabs">
  <ul>
  

    <li><a href="#tabs-1">DESCRIPTION</a></li>
    <li><a href="#tabs-2">ARTICLES SIMILAIRES</a></li>

  </ul>


     <div class="cadre" id="tabs-1">
     
     <div class="infos-description">
     
     <div class="title"><?=$libelle?></div>
   <?=$details?>
   </div>
   
   <div class="infos-pratiques">
					<div><br><span class="color-texte">Informations <span class="bold">Techniques</span></span></div><br>	
							<div><span class="bold">DIMENSIONS</span></div>
			    <div class="color-texte infos">
							    	<div class="left"><?=$var_shop_hauteur?></div><div class="right"><?=$hauteur?>&nbsp;cm</div>
			    			    			        <div class="left">Longueur</div><div class="right"><?=$longueur?>&nbsp;cm</div>
			       
			 				       <div class="left">Profondeur</div><div class="right"><?=$profondeur?>&nbsp;cm</div><br>
			
				</div>
										<div><span class="bold">COLIS</span></div>
				<div class="color-texte">
			    			        <div class="left">Nombre de colis</div><div class="right" id="nb_colis"><?=$nbrcolis?></div>
			    			    			       <div class="left">Poids total</div><div class="right" id="poids"><?=$poids?>&nbsp;kg</div>
			    </div>
			    <br>
									    <span class="color-texte">Informations <span class="bold">Pratiques</span></span>
			<ul>
				<li><span><?=$infospratiques?></span></li>											</ul>
							</div>
							<br clear="all"/>
</div>


     <div class="cadre" id="tabs-2">
   test2
   
   <br clear="all"/>
</div>

</div>


<script>
  $(function() {
    $( "#product_tabs" ).tabs();
  });
  </script>

      </div>

  <script type="text/javascript">
      maxquantites=0;
  $('input[id^="size_"]').change(function() {
	  var id=$(this).attr('id').replace("size_","");
	  $("#quantity").val(1);
      maxquantites=getQuantity(id);
	 /* $("#quantity").spinner("destroy");
	  $("#quantity").spinner({min:1,max:getQuantity(id),stepping: 1,allowNull: false});*/
  });

  $('input[id^="unit_"]').change(function() {
      $("#stockout").hide();
      $("#stockin").show();
      var id=$(this).attr('id').replace("unit_","");

      $("#quantity").val(1);
      maxquantites=getQuantity(id);

      if (maxquantites=0)
      {
          $("#stockin").hide();
          $("#stockout").show();
      }

  });


/*

  $("#quantity").spinner({min:1,max:<?php echo $max_quantity; ?>,stepping: 1});


*/
      maxquantites=<?php echo $max_quantity; ?>;

      $('#inc').click(function() {
          c=$("#quantity").val();
          if (c<maxquantites){


          $("#quantity").val(++c);}

      });
      $('#dec').click(function() {
          if ($("#quantity").val()>=2){
          $("#quantity").val( $("#quantity").val()-1);}

      });

  </script>
  
<?php }else{
	
	showError($var_shop_productnotfound);
} ?>
  
 <?php

}
else {

    showError($var_shop_productnotfound);
}
    ?>